#define _CRT_SECURE_NO_WARNINGS

class Solution {
public:
    int findContentChildren(vector<int>& g, vector<int>& s) {
        sort(g.begin(), g.end());
        sort(s.begin(), s.end());
        int ret = 0;
        for (int i = 0; i < s.size(); i++)
        {
            if (ret == g.size())
                break;
            if (g[ret] <= s[i])
                ret++;
        }
        return ret;
    }
};

class Solution {
public:
    int wiggleMaxLength(vector<int>& nums) {
        int ret = 1;
        int prev = 0;
        int cur = 0;
        if (nums.size() == 1)
            return ret;
        for (int i = 1; i < nums.size(); i++)
        {
            cur = nums[i] - nums[i - 1];
            if ((prev > 0 && cur < 0) || (prev < 0 && cur>0) || (prev == 0 && cur != 0))
            {
                ret++;
                prev = cur;
            }
        }
        return ret;
    }
};

class Solution {
public:
    int maxSubArray(vector<int>& nums) {
        int ret = nums[0];
        int tmp = 0;
        for (int i = 0; i < nums.size(); i++)
        {
            tmp += nums[i];
            if (ret < tmp)
                ret = tmp;
            if (tmp < 0)
                tmp = 0;
        }
        return ret;
    }
};